package edu.cuit.avatar.common.handler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/26 9:18
 */
public class MapResultSetHandler implements ResultSetHandler<Map<String,?>> {
    @Override
    public Map<String, ?> process(ResultSet rs) throws SQLException {
        if(rs.next()){
            var map = new HashMap<String, Object>();
            var metaData = rs.getMetaData();
            for(var i = 1; i <= metaData.getColumnCount(); i++)
                map.put(metaData.getColumnLabel(i), rs.getObject(i));
            return map;
        }
        return null;
    }
}
